API Corner - Moving a Window

level: intermediate

by Alyce Watson [http://alycesrestaurant.com/]

Home

Wire 1.0

Gif Viewer

Report Generation

Flow Charting

Stylebits Corner

Tip Corner

API Corner

CodeAChrome

Sprite Byte

Control Panel Applets

HTTPS Data

Eddie

Submissions

Index


We can move and resize any window or control with the MoveWindow API call. The coordinates for the x and y locations of a window are relative to the upper left corner of the desktop. If the API call is used to move or resize a control, the coordinates are relative to the upper left corner of the window's workspace, which is called the Client Area.

Liberty BASIC includes a LOCATE command for moving controls, so the API version is included here just as an example. For use of the resizehandler, see Tip Corner. Liberty BASIC does not currently have a native function for moving or resizing an open window, so we must use an API call to do it. We've used this API call in Eddie after the window is opened, to force the resizehandler to be activated. That way, we can size the CodeAChrome control to fit properly into the client area of Eddie's window, no matter what type of display scheme the user has in force.

To move or resize a window, use the handle of the window obtained with the HWND() function.

    hMain = HWND(#main)

    calldll #user32, "MoveWindow",_
    hMain as ulong, _       'window handle
    10 as long,_            'x location of window
    20 as long,_            'y location of window
    730 as long,_           'desired width of window
    590 as long,_           'desired height of window
    1 as boolean,_          'repaint flag,0=false,1=true
    ret as long             'nonzero=success

To move or resize a control, use the handle of the control obtained with the HWND() function.

    hButton = HWND(#main.button1)

    calldll #user32, "MoveWindow",_
    hButton as ulong, _     'control handle
    10 as long,_            'x location of control
    45 as long,_            'y location of control
    100 as long,_           'desired width of control
    50 as long,_            'desired height of control
    1 as boolean,_          'repaint flag,0=false,1=true
    ret as long             'nonzero=success


Home

Wire 1.0

Gif Viewer

Report Generation

Flow Charting

Stylebits Corner

Tip Corner

API Corner

CodeAChrome

Sprite Byte

Control Panel Applets

HTTPS Data

Eddie

Submissions

Index